package com.convict.hello;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class HelloActivity extends Activity {
	
	private static final String MAIN_LOG = "MAIN_LOG";
	
	private EditText multiplierOne = null;
	private EditText multiplierTwo = null;
	
	private Button btnRelative;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.i(MAIN_LOG, "one-----create");
		System.out.println("------------------------------------------------");
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_hello);
		TextView tv = (TextView)findViewById(R.id.textView);
		tv.setText(R.string.hello_world);
		multiplierOne = (EditText)findViewById(R.id.multiplierOne);
		multiplierTwo = (EditText)findViewById(R.id.multiplierTwo);
		Button bt = (Button)findViewById(R.id.button);
		bt.setText(R.string.btText);
		//展示乘积
		bt.setOnClickListener(new BtClickListener());
		

		//展示relative部局
		btnRelative = (Button)findViewById(R.id.activity_relative);
		btnRelative.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(HelloActivity.this, RelativeActivity.class);
				HelloActivity.this.startActivity(intent);
			}
		});
	}
	
	
	class BtClickListener implements OnClickListener{

		@Override
		public void onClick(View v) {
			Intent intent = new Intent();
			
			double one = Double.valueOf(multiplierOne.getText().toString());
			double two = Double.valueOf(multiplierTwo.getText().toString());
			intent.putExtra("multiplierOne", one);
			intent.putExtra("multiplierTwo", two);
			
			intent.setClass(HelloActivity.this, Result.class);
			HelloActivity.this.startActivity(intent);
		}
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.hello, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		if(R.id.menu_finish == item.getItemId()){
			Log.i(MAIN_LOG, "selected finish menu item......");
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	protected void onDestroy() {
		Log.i(MAIN_LOG, "fires-----destroy");
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		Log.i(MAIN_LOG, "fires-----pause");
		super.onPause();
	}

	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		Log.i(MAIN_LOG, "fires-----restart");
		super.onRestart();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		Log.i(MAIN_LOG, "fires-----resume");
		super.onResume();
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		Log.i(MAIN_LOG, "fires-----start");
		super.onStart();
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		Log.i(MAIN_LOG, "fires-----stop");
		super.onStop();
	}

}
